// Copyright (c) [Year] [name of copyright holder]
// [Software Name] is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2. 
// You may obtain a copy of Mulan PSL v2 at:
//          http://license.coscl.org.cn/MulanPSL2 
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
// See the Mulan PSL v2 for more details.

/*!
 * \autor captainpeng
 * \date 2019-5-15
 * \update 2019-5-15
 * \version 1.0
 * \copyright
 */

#ifndef MY_MEMFUNC_HPP
#define MY_MEMFUNC_HPP

namespace my{
    
    using memAllocFunc = void*(*)(size_t);
    using memFreeFunc = void(*)(void *);
    
    template<typename Type>
    class memFunc{
        memFunc() = delete;
    public:
        using type = Type;
        // using fnAllocType = memAllocFunc;
        // using fnFreeType = memFreeFunc;

        static void * Alloc(size_t size){
            return static_cast<void *>(new type[size]);
        }
	
        static void Free(void * p){
            delete [] static_cast<type *>(p);
        }
    };

    template<typename Type, typename AllocCallBack, typename FreeCallBack>
    class memDebugFunc{
        memDebugFunc() = delete;
    public:
        using type = Type;

        static const AllocCallBack * & C1(){
            static const AllocCallBack * c1;
            return c1;
        }

        static const FreeCallBack * & C2(){
            static const FreeCallBack * c2;
            return c2;
        }
        
        static void * Alloc(size_t size){
            (*C1())();
            return memFunc<type>::Alloc(size);
        }
	
        static void Free(void * p){
            (*C2())();
            memFunc<type>::Free(p);
        }

    };
}

#endif
